package com.tuanbiao.presenter;

import com.hzjq.data.entity.BlastEntity;
import com.tuanbiao.base.mvp.BasePresenter;
import com.tuanbiao.controllers.LogController;

/**
 * @author abiao
 * @since 2022/4/28 17:01
 */
public class BlastLogBackupPresenter extends BasePresenter<LogController.Model, LogController.BackupView> implements LogController.BackupPresenter {
    private int mPageIndex = 1;

    public BlastLogBackupPresenter(LogController.Model model, LogController.BackupView rootView) {
        super(model, rootView);
    }

    @Override
    public void refresh() {
        mPageIndex = 1;
        queryBlastCopy(mPageIndex);
    }

    @Override
    public void loadMore() {
        mPageIndex++;
        queryBlastCopy(mPageIndex);
    }

    @Override
    public void restore(BlastEntity entity) {
        mModel.restoreBlastCopy(entity, unused -> {
            mRootView.showMessage("恢复成功！");
            refresh();
        });
    }

    private void queryBlastCopy(int pageIndex) {
        mModel.queryBlastCopy(pageIndex, blastEntities -> {
            if (pageIndex == 1) mRootView.setItems(blastEntities);
            else mRootView.addItems(blastEntities);
        });
    }
}
